package com.calis.ill.order.service.impl;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.calis.ill.order.entity.User;
import com.calis.ill.order.repository.UserRepository;
import com.calis.ill.order.service.api.UserService;
import com.fasterxml.jackson.databind.ObjectMapper;

@Service("userService")
public class UserServiceImpl implements UserService{
	
	@Autowired
	UserRepository repo;
	
	ObjectMapper mapper = new ObjectMapper();

	public void add(String account, String username, String password, BigDecimal balance) {
		User u = new User();
		u.setAccount(account);
		u.setUsername(username);
		u.setPassword(password);
		u.setBalance(balance);
		repo.save(u);
	}

	public String getUser(String account) throws Exception {
		User u = repo.findByAccount(account);
		String rst = mapper.writeValueAsString(u);
		return rst;
	}

}
